<!DOCTYPE html>
<html>
<head>
<?php include_once VIEWS.'inc/head.php'; ?>
</head>

<body>
   
    <div class="main news js-win-h js-news">
         <?php include_once VIEWS.'inc/header.php'; ?>
        <div class="box">
            <div class="calendar">
        		<div class="wrap">
                    <div class="cal-week">
                        <ul class="f-cb">
                            <li class="pull-left">日</li>
                            <li class="pull-left">一</li>
                            <li class="pull-left">二</li>
                            <li class="pull-left">三</li>
                            <li class="pull-left">四</li>
                            <li class="pull-left">五</li>
                            <li class="pull-left">六</li>
                        </ul>
                    </div>
                    <div class="cal-day">
                        <ul class="f-cb">
                            
                        </ul>
                    </div>
                </div>
                <div class="cal-bar f-cb">
                    <a id="prev-moon" class="pull-left" href="javascript:void(0)"></a>
                    <p class="cal-ym pull-left"><span class="cal-year">2016</span>.<span class="cal-moon">5</span></p>
                    <a id="next-moon" class="pull-left" href="javascript:void(0)"></a>
                </div>  
                <img class="news-bg" src="<?php echo static_file('web/img/news-bg.png'); ?>">
            </div>
            <?php include_once VIEWS.'inc/footer.php'; ?>
        </div>
    </div>
    <div class="ajax-bg"></div>
    <div class="news-list-box">
        
    </div>
    <div class="news-info-box">
        
    </div>
</body>
</html>
<script type="text/javascript">
    $(function(){
            $('.js-nar-bar .link').eq(3).addClass('cur');
            
            $('.mCustomScrollbar2').mCustomScrollbar({
                autoDraggerLength: true,
                scrollSpeed:200,
                scrollbarPosition: 'outside'
            });
            //日历
            var moon_cn = new Array();
            var data_arr= new Array();
            moon_cn[1] = "1";
            moon_cn[2] = "2";
            moon_cn[3] = "3";
            moon_cn[4] = "4";
            moon_cn[5] = "5";
            moon_cn[6] = "6";
            moon_cn[7] = "7";
            moon_cn[8] = "8";
            moon_cn[9] = "9";
            moon_cn[10] = "10";
            moon_cn[11] = "11";
            moon_cn[12] = "12";
            var _today = new Date();
            var _today_y = _today.getFullYear();
            var _today_m = _today.getMonth();
            var _today_d = _today.getDate();
            var now_y = _today_y;
            var now_m = _today_m;

            function showdate(y,m){
                /*模拟数据*/
                // 日期，对应日期的数据条数
                data_arr=[
                          <?php foreach($news as $k=>$v):?>
                    ['<?php echo $k;?>',<?php echo $v;?>],
                    			<?php endforeach;?>
                ];

                var m = m+1;
                if(m == 12){
                    var nextm = 1;
                    var nexty = y+1;
                }else{
                    var nextm = m+1;
                    var nexty = y;
                }
                var new_date = new Date(y+"/"+m+"/1");//取第一天  
                var new_nextdate = new Date(nexty+"/"+nextm+"/1");//取下个月第一天
                var new_day = new_date.getDay();//取第一天是星期几
                var d_num = (new Date(new_nextdate.getTime()-1000*60*60*24)).getDate();//取总天数
                var d_prev_num = (new Date(new_date.getTime()-1000*60*60*24)).getDate();//取上月总天数
                var laster_day = (new Date(new_nextdate.getTime()-1000*60*60*24)).getDay();//取最后一天周几
                var _d_prev_day = d_prev_num - new_day + 1;
                var _ist=0;
                $(".cal-day ul").html("");
                if(y == _today_y && m == _today_m + 1){
                    _ist = 1;
                }
                for (var i = 0; i < new_day; i++) {
                    /*后--添加非本月的日期*/
                    var _d = _d_prev_day + i;
                    
                    $(".cal-day ul").append("<li class='pull-left'> </li>");
                }
                /* var data_arr[j][0].split("-");*/
                function addRed(_data_arr,_date_sw,_i){
                    var count_sw=0;
                    for(var j=0;j<_data_arr.length;j++){
                        if(_data_arr[j][0]==_date_sw){
                            num_f=j;
                            count_sw++; 
                        }
                    }
                    if(count_sw<1){
                        $(".cal-day ul").append( "<li class=' pull-left' data-id='"+_date_sw+"'>"+_i+"</li>"); 
                    }else if(count_sw==1){
                        $(".cal-day ul").append( "<li class=' pull-left red' data-num='"+data_arr[num_f][1]+"' data-id='"+_date_sw+"'>"+_i+"</li>"); 
                    }
                }
                function addGray(_data_arr,_date_sw,_i){
                    var count_sw=0;
                    for(var j=0;j<_data_arr.length;j++){
                        if(_data_arr[j][0]==_date_sw){
                            num_f=j;
                            count_sw++; 
                        }
                    }
                    if(count_sw<1){
                        $(".cal-day ul").append( "<li class=' pull-left' data-id='"+_date_sw+"'>"+_i+"</li>"); 
                    }else if(count_sw==1){
                        $(".cal-day ul").append( "<li class=' pull-left gray' data-num='"+data_arr[num_f][1]+"' data-id='"+_date_sw+"'>"+_i+"</li>"); 
                    }
                }
                for (var i = 1; i <= d_num; i++) {
                    var date_sw=y+'-'+m+'-'+i;
                    var num_f =0;
                    if(_ist == 1 && i == _today_d){
                        var count_sw=0;
                        for(var j=0;j<data_arr.length;j++){
                            if(data_arr[j][0]==date_sw){
                                num_f=j;
                                count_sw++; 
                            }
                        }
                        if(count_sw<1){
                            $(".cal-day ul").append( "<li class='today pull-left' data-id='"+date_sw+"'>"+i+"</li>"); 
                        }else if(count_sw==1){
                            $(".cal-day ul").append( "<li class='today pull-left red' data-num='"+data_arr[num_f][1]+"' data-id='"+date_sw+"'>"+i+"</li>"); 
                        }
                    }else{
                        if(_today_y>y){
                            addGray(data_arr,date_sw,i);
                        }else if(_today_y<y){
                            addRed(data_arr,date_sw,i);
                        }else if(_today_y==y){
                            if(_today_m+1>m){
                                addGray(data_arr,date_sw,i);
                            }else if(_today_m+1<m){
                                 addRed(data_arr,date_sw,i);
                            }else if(_today_m+1==m){
                                if(i<_today_d){
                                     addGray(data_arr,date_sw,i);
                                }else{
                                    addRed(data_arr,date_sw,i);
                                }
                            }
                        }
                    }
                }
                for (var i = 0; i < 6 - laster_day; i++) {
                    /*前--添加非本月的日期*/
                    var _d = i+1;
                    $(".cal-day ul").append("<li class='pull-left'> </li>");
                };
                $(".cal-moon").html(moon_cn[m]);
                $(".cal-year").html(y);
            }
            function changeMoon(y,m){
                if( m < 0){
                    var _m = 11;
                    var _y = y - 1;
                }else if( m > 11){
                    var _m = 0;
                    var _y = y + 1;
                }else{
                    var _m = m;
                    var _y = y;
                }
                var _nowarr = new Array();
                _nowarr[1] = _m;
                _nowarr[0] = _y;
                return _nowarr;
            }
            $("#prev-moon").click(function(){
                var _pm = now_m - 1;
                var _nowarr = changeMoon(now_y,_pm);
                now_y = _nowarr[0];
                now_m = _nowarr[1];
                showdate(now_y,now_m);
            });
            $("#next-moon").click(function(){
                var _pm = now_m + 1;
                var _nowarr = changeMoon(now_y,_pm);
                now_y = _nowarr[0];
                now_m = _nowarr[1];
                showdate(now_y,now_m);
            });
            var _num=0;

            $(document).click(function(e){
                /*点击空白处隐藏搜索*/
                if($(e.target).hasClass('js-news')||$(e.target).parents().hasClass('js-news')){
                    if(!$(e.target).parent().parent().hasClass('cal-day')){
                        if(!$('.news-info-box .wrap').is(':hidden')){ 
                            $('.calendar').removeClass('t-shadow');
                            $('.news-info-box').css({
                                 opacity: 0,
                                scale:0
                            }).hide();
                            if($('.news-list-box .wrap').is(':hidden')){ 
                                $('.news-list-box').show().animate({
                                    scale: 1,
                                    opacity: 1
                                },600);
                                $('.calendar').addClass('t-shadow');
                            }
                        }else{
                            if(!$('.news-list-box .wrap').is(':hidden')){ 
                                $('.news-list-box').css({
                                     opacity: 0,
                                    scale:0
                                }).empty().hide();
                                $('.calendar').removeClass('t-shadow');
                            }
                        }
                    }
                }
            });

            $(document).on('click','.news-info-box .back-btn',function(){
                $('.calendar').removeClass('t-shadow');
                $('.news-info-box').css({
                     opacity: 0,
                    scale:0
                }).hide();
                
                if(_num>1){
                    $('.news-list-box').show().animate({
                        scale: 1,
                        opacity: 1
                    },600);
                    $('.calendar').addClass('t-shadow');
                }
            });

            $(document).on('click','.news-list-box .back-btn',function(){
                $('.news-list-box').css({
                     opacity: 0,
                    scale:0
                }).empty().hide();
                $('.calendar').removeClass('t-shadow');
            });
            $(document).on('click','.news-list-box .js-list',function(){
                var _listId= $(this).index();
                var newsId=$(this).attr('data-id');
                
                $('.news-list-box').css({
                     opacity: 0,
                    scale:0
                }).hide();
                $('.calendar').removeClass('t-shadow');
                $('.news-info-box').show().css({
                    scale:0
                });
                
                $.ajax({
                    url : '<?php echo site_url("news_info_ajax?news_id=");?>'+newsId,
                    success:function(html){
                        $('.news-info-box').empty().animate({
                            scale: 1,
                            opacity: 1
                        },600,function(){
                            $('.news-info-box').append(html);
                            /*模拟滚动条*/
                            $('.mCustomScrollbar2').mCustomScrollbar({
                                autoDraggerLength: true,
                                scrollSpeed:200,
                                scrollbarPosition: 'outside'
                            });
                            $('.news-info-box .wrap').delay(200).animate({
                                opacity: 1
                            },600);
                            $('.calendar').addClass('t-shadow');
                        });
                    }
                });
            });
            $(".cal-day").on("click","li",function(){
                if(($('.news-info-box ').is(':hidden')&&$('.news-list-box ').is(':hidden'))){
                    if($(this).hasClass('red')||$(this).hasClass('gray')){
                        _num=$(this).attr('data-num');
                        var _id=$(this).attr('data-id');
                        /*如果数据大于一条，出现列表，如果只有一条，直接出现详情*/
                        if(_num>1){
                            $('.news-list-box').show().css({
                                scale:0
                            });
                            $.ajax({
                                url : '<?php echo site_url("news_list_ajax?id=");?>'+_id,
                                success:function(html){
                                    $('.news-list-box').animate({
                                        scale: 1,
                                        opacity: 1
                                    },600,function(){
                                        $('.news-list-box').append(html);
                                        /*模拟滚动条*/
                                        $('.mCustomScrollbar').mCustomScrollbar({
                                            autoDraggerLength: true,
                                            scrollSpeed:200,
                                            scrollbarPosition: 'outside'
                                        });
                                        $('.news-list-box .wrap').delay(200).animate({
                                            opacity: 1
                                        },600);
                                        $('.calendar').addClass('t-shadow');
                                    });
                                }
                            });
                        }else{
                            var newsId=$(this).attr('data-id');
                            $('.news-info-box').show().css({
                                scale:0
                            });
                            $.ajax({
                                url : '<?php echo site_url("news_info_ajax?news_id=");?>'+newsId,
                                success:function(html){
                                    $('.news-info-box').empty().animate({
                                        scale: 1,
                                        opacity: 1
                                    },600,function(){
                                        $('.news-info-box').append(html);
                                        /*模拟滚动条*/
                                        $('.mCustomScrollbar2').mCustomScrollbar({
                                            autoDraggerLength: true,
                                            scrollSpeed:200,
                                            scrollbarPosition: 'outside'
                                        });
                                        $('.news-info-box .wrap').delay(200).animate({
                                            opacity: 1
                                        },600);
                                         $('.calendar').addClass('t-shadow');
                                    });
                                }
                            });
                        }
                    }
                }
            });

            showdate(_today_y,_today_m);
    })
</script>